
(function(ns){

var GroundScene = ns.GroundScene = Hilo.Class.create({
    Extends: Hilo.Container,
    constructor: function(properties){
		//console.log(JSON.stringify(properties))
        GroundScene.superclass.constructor.call(this, properties);
        this.init(properties);
    },
	huTween:null,
    init: function(properties){
		//console.log(properties)
        //准备Get Ready!
        var waiground = new Hilo.Bitmap({
			id:"waiground",
            image: properties.image[0],
            rect: [0, 0, 575, 219]
        });

        //内背景
        var neiground = new Hilo.Bitmap({
			id:"neiground",
            image: properties.image[1],
            rect: [0, 0, 229, 73],
			visible: false,
        });
		//内加
		var neijia = new Hilo.Bitmap({
			id:"neijia",
		    image: properties.image[2],
		    rect: [0, 0, 229, 73],
			visible: true
		});
		//泥巴
		var niba = new Hilo.Bitmap({
			id:"niba",
		    image: properties.image[3],
		    rect: [0, 0, 121, 39],
			visible: true
		});
		//加手、壶、倒水、转换特效三个精灵
		var shou = new Hilo.Bitmap({
			id:"shou",
		    image: properties.image[4],
		    rect: [0, 0, 102, 114],
			visible: true
		});
		
        
        //确定getready和tap的位置
		// console.log(this.width - tap.width) 
		// console.log(this.width - tap.width >> 0)
        waiground.x = this.width - waiground.width >> 1;
        waiground.y = this.height;
		
        neiground.x = this.width - neiground.width + 20 >> 1;
        neiground.y = this.height + waiground.height * .5 + 20 >>1 ;
		
		neijia.x = this.width - neijia.width + 20 >> 1;
		neijia.y = this.height + waiground.height * .5 + 20 >>1 ;
		
		niba.x = this.width - niba.width + 40 >> 1;
		niba.y = this.height + waiground.height * .5 + 75 >>1 ;
		niba.depth = 99
		
		shou.x = this.width - shou.width + 50 >> 1;
		shou.y = -60;
		
        this.addChild(waiground,neiground,neijia,niba,shou);
		
		Hilo.Tween.to(shou, {y:shou.y-10}, {duration:500,ease:null, reverse:true, loop:true});
	
    },
	doShow: function(item){
		// console.log("123")
		//console.log(item)
		let that = this
		
		if(!item.myWatermelon && utilsClass.isEmpty(item.watermelon)){
			this.getChildById('neijia').visible = true
			this.getChildById('neiground').visible = false
			this.getChildById('niba').visible = false
			this.getChildById('hu').visible = false
			this.getChildById('zhongzi').visible = false
			this.getChildById('miao').visible = false
			this.getChildById('smallgua').visible = false
			this.getChildById('biggua').visible = false
			this.getChildById('txicon').visible = false
			this.getChildById('jsicon').visible = false
			this.getChildById('txicon').stop()
			this.getChildById('miao').stop()
			this.getChildById('smallgua').stop()
			this.getChildById('biggua').stop()
			this.getChildById('jsicon').stop()
			this.getChildById('hu').y = -60;
			
			this.getChildById('jsicon').y = -50;
		}else if(item.myWatermelon && !utilsClass.isEmpty(item.watermelon) && item.watermelon.curveValue==0){
			this.getChildById('neijia').visible = false
			this.getChildById('neiground').visible = true
			this.getChildById('niba').visible = true
			this.getChildById('hu').visible = true
			this.getChildById('zhongzi').visible = true
			this.getChildById('miao').visible = false
			this.getChildById('smallgua').visible = false
			this.getChildById('biggua').visible = false
			this.getChildById('txicon').visible = false
			this.getChildById('jsicon').visible = false
			this.getChildById('shou').visible = false
			this.getChildById('hu').y = -60;
			
			this.getChildById('jsicon').y = -90;
		}else if(item.myWatermelon && !utilsClass.isEmpty(item.watermelon) && item.watermelon.curveValue==50){
			this.getChildById('neijia').visible = false
			this.getChildById('neiground').visible = true
			this.getChildById('neijia').visible = false
			this.getChildById('jsicon').visible = false
			this.getChildById('zhongzi').visible = false
			this.getChildById('miao').visible = true
			this.getChildById('smallgua').visible = false
			this.getChildById('biggua').visible = false
			this.getChildById('txicon').visible = false
			this.getChildById('jsicon').visible = false
			this.getChildById('shou').visible = false
			this.getChildById('hu').y = -100;

			this.getChildById('jsicon').y = -50;
		}else if(item.myWatermelon && !utilsClass.isEmpty(item.watermelon) && item.watermelon.curveValue==100){
			this.getChildById('neijia').visible = false
			this.getChildById('neiground').visible = true
			this.getChildById('jsicon').visible = false
			this.getChildById('zhongzi').visible = false
			this.getChildById('miao').visible = false
			this.getChildById('smallgua').visible = true
			this.getChildById('biggua').visible = false
			this.getChildById('txicon').visible = false
			this.getChildById('jsicon').visible = false
			this.getChildById('shou').visible = false
			this.getChildById('jsicon').visible = false
			this.getChildById('hu').y = -115;
		
			this.getChildById('jsicon').y = -50;
		}else if(item.myWatermelon && !utilsClass.isEmpty(item.watermelon) && item.watermelon.curveValue==150){
			this.getChildById('neijia').visible = false
			this.getChildById('neiground').visible = true
			this.getChildById('jsicon').visible = false
			this.getChildById('zhongzi').visible = false
			this.getChildById('miao').visible = false
			this.getChildById('smallgua').visible = false
			this.getChildById('biggua').visible = true
			this.getChildById('txicon').visible = false
			this.getChildById('jsicon').visible = false
			this.getChildById('shou').visible = false
			this.getChildById('jsicon').visible = false
			this.getChildById('hu').y = -130;
			
			this.getChildById('jsicon').y = -90;
		}
		//初始化加入进来的hu
		this.getChildById('hu').x = this.width - this.getChildById('hu').width + 50 >> 1;
		//浇水
		this.getChildById('jsicon').x = this.width - this.getChildById('jsicon').width + 90 >> 1;
		
		//zhongzi
		this.getChildById('zhongzi').x = this.width - this.getChildById('hu').width + 80 >> 1;
		this.getChildById('zhongzi').y = 60;
		//苗
		this.getChildById('miao').x = this.width - this.getChildById('hu').width-20 >> 1;
		this.getChildById('miao').y = 5;
		//小瓜
		this.getChildById('smallgua').x = this.width - this.getChildById('hu').width-10 >> 1;
		this.getChildById('smallgua').y = 0;
		//大瓜
		this.getChildById('biggua').x = this.width - this.getChildById('hu').width-40 >> 1;
		this.getChildById('biggua').y = -30;
		//特效
		this.getChildById('txicon').x = this.width - this.getChildById('txicon').width + 50 >> 1;
		this.getChildById('txicon').y = 20;
		
		
		//动作
		this.huTween = Hilo.Tween.to(this.getChildById('hu'), {x:this.getChildById('hu').x ,y:this.getChildById('hu').y-10, rotation:0}, {duration:500,ease:null, reverse:true, loop:true});
		//console.log(this.children)
			
		//this.swapChildrenAt(3,6)
		//设置index
		this.setChildIndex(this.getChildById('niba'),this.getNumChildren()-1)
		this.setChildIndex(this.getChildById('txicon'),this.getNumChildren()-2)
		//点击
		this.getChildById('neijia').on(Hilo.event.POINTER_START, function(e) {
			   e.stopImmediatePropagation && e.stopImmediatePropagation();
			   
			  postAjax2({
			      id: 2,
			      method: "watermelon_getwatermelon",
			      params: {
			          "authKey": window.game.authKey,
			          "activityId": 41
			      }
			  }, function (datas) {
			       console.log(JSON.stringify(datas))
					if(!utilsClass.isEmpty(datas)){
						window.game.InitData = datas
						if(!utilsClass.isEmpty(datas.message)){
							$.alert(datas.message,"提示",function(){});
							// return;
						}else{
							Hilo.Tween.to(that.getChildById('shou'), {alpha:0}, {duration:200});
							Hilo.Tween.to(that.getChildById('neijia'), {alpha:0}, {duration:600});
							that.getChildById('neiground').visible = true
							that.getChildById('niba').visible = true
							that.getChildById('hu').visible = true
							//zhongzi
							that.getChildById('zhongzi').visible = true
							that.getChildById('zhongzi').isReady = true
							that.getChildById('txicon').visible = true
							that.getChildById('zhongzi').play()
							that.getChildById('txicon').play()
						}
					}
			  });
			   //console.log(window.game.InitData)
			   
			  
			   //this.getChildById('neijia').visible = false
			   // this.getChildById('neiground').visible = true
			   // this.getChildById('niba').visible = true
			   // this.getChildById('hu').visible = true
			   // //zhongzi
			   // this.getChildById('zhongzi').visible = true
			   // this.getChildById('zhongzi').isReady = true
			   // this.getChildById('txicon').visible = true
			   // this.getChildById('zhongzi').play()
			   // this.getChildById('txicon').play()
		}.bind(this))
		
		this.getChildById('shou').on(Hilo.event.POINTER_START, function(e) {
			   e.stopImmediatePropagation && e.stopImmediatePropagation();
			   postAjax2({
			       id: 2,
			       method: "watermelon_getwatermelon",
			       params: {
			           "authKey": window.game.authKey,
			           "activityId": 41
			       }
			   }, function (datas) {
			        console.log(JSON.stringify(datas))
					if(!utilsClass.isEmpty(datas)){
						window.game.InitData = datas
						if(!utilsClass.isEmpty(datas.message)){
							$.alert(datas.message,"提示",function(){});
							//return;
						}else{
							Hilo.Tween.to(that.getChildById('neijia'), {alpha:0}, {duration:600});
							Hilo.Tween.to(that.getChildById('shou'), {alpha:0}, {duration:200});
							that.getChildById('neiground').visible = true
							that.getChildById('niba').visible = true
							that.getChildById('hu').visible = true
							//zhongzi
							that.getChildById('zhongzi').visible = true
							that.getChildById('zhongzi').isReady = true
							that.getChildById('txicon').visible = true
							that.getChildById('zhongzi').play()
							that.getChildById('txicon').play()
						}
						
					}
			   });
			   //console.log(window.game.InitData)
			   
			   
			   
			   //this.getChildById('neijia').visible = false
			   
		}.bind(this))
		
	}
});

})(window.game);